package com.andyage.admin.action;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.andyage.admin.service.IAdcommentService;
import com.andyage.admin.bean.AdcommentBean;

import net.sf.json.JSONObject;

@Controller
@RequestMapping("/admin")
public class AdcommentAction {
	@Resource
	private IAdcommentService iadcommentService;
	@RequestMapping("/queryAdcommentInfo")
	public void queryAdcommentInfo(HttpServletRequest request,HttpServletResponse response,AdcommentBean adcomment) {
		String json=null;
		try {
			json=iadcommentService.queryAdcommentInfo(adcomment);
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.setContentType("text/html;charset=utf-8");
		try {
			response.getWriter().print(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	@RequestMapping("/deleteAdcommentInfo")
	public  void deleteAdcommentInfo(HttpServletRequest request,HttpServletResponse response) {
		int flag=0;
		String commentId=request.getParameter("commentId");
		JSONObject json=new JSONObject();
		try {
			flag=iadcommentService.deleteAdcommentInfo(commentId);
			if(flag!=0){
				json.accumulate("reslut", 1);
				json.accumulate("tips", "删除成功");
			}else{
				json.accumulate("reslut", 0);
				json.accumulate("tips", "删除失败");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.setContentType("text/html;charset=utf-8");
		try {
			response.getWriter().print(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	@RequestMapping("/updateAdcommentInfo")
	public void updateAdcommentInfo(HttpServletRequest request,HttpServletResponse response) throws Exception {
		AdcommentBean adcomment=new AdcommentBean();
		String commentId=request.getParameter("commentId");
		String commentAnswer=request.getParameter("commentAnswer");
		String commentIsShow=request.getParameter("commentIsShow");
		System.out.println("---------------->"+commentIsShow);
		if(commentIsShow!=null&&!"".equals(commentIsShow)){
		if("是".equals(commentIsShow)||"1".equals(commentIsShow)){
			adcomment.setCommentIsShow(true);
		}else{
			adcomment.setCommentIsShow(false);
		}
		}
		adcomment.setCommentIsAnswer(true);
		adcomment.setCommentId(commentId);
		adcomment.setCommentAnswer(commentAnswer);
		int flag=iadcommentService.updateAdcommentInfo(adcomment);
		JSONObject json=new JSONObject();
		if(flag!=0){
			json.accumulate("reslut", 1);
			json.accumulate("tips", "修改成功");
		}else{
			json.accumulate("reslut", 0);
			json.accumulate("tips", "修改失败");
		}
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().print(json);
	}
}
